package com.coder520.sync_learning.demo;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

public class FlagThreadExit {
    static  class  Mytask extends Thread{
        private volatile boolean close=false;
        @Override
        public void run() {
            System.out.println("我要开始工作");

            while (!close&&!isInterrupted()){
                System.out.println("我正在运行");
            }
            System.out.println("我要结束了");
        }

        private void close(){
            this.close=true;
            this.interrupt();
        }
    }
    
    public static void main(String[] args) throws InterruptedException {
        Mytask t=new Mytask();
        t.start();
        TimeUnit.MINUTES.sleep(1);
        System.out.println("系统也要结束了");

        t.close();

    }
}
